package com.zprmb.udzt;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.zprmb.udzt.activity.InvestLoginDialog;
import com.zprmb.udzt.model.ZhiTouBaoModel;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.GuideAlertDialog;
import com.zprmb.udzt.util.GuideAlertDialog.OnSureClickListener;
import com.zprmb.udzt.util.LogUtils;
import com.zprmb.udzt.util.Regular;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.util.VolleryUtil3;

import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class V6DexterityActivity2 extends BaseActivity implements OnClickListener, OnSureClickListener, InvestLoginDialog.OnSureClickListener, PullToRefreshBase.OnRefreshListener<ScrollView> {

    private FragmentManager fm;

    DecimalFormat df = new DecimalFormat("###0.0000");
    DecimalFormat df2 = new DecimalFormat("###0.00");
    private List<String> list = new ArrayList<String>();

    private String id, url, desc = "";
    private Button btn_dexterity_invest;
    private TextView et_amount;

    private boolean flag;
    private int increaseNum = 0;

    private TextView tv_title;


    private TextView tv_desc;

    private boolean islogin;

    private String type;
    private GuideAlertDialog mAlertDialog;
    private TextView v6_de_rate_dwon, v6_de_rate_up;
    private TextView tv_millionAccrua;
    private Double millionAccrua = (double) 0, rate = (double) 0;
    private String ref = "", linkurl;

    InvestLoginDialog mAlertDialog2;
    private PopupWindow pop;
    private LinearLayout layout_calculator, layout_share;

    private ImageView iv_v4_nonetwork1;
    //项目详情
    private TextView text_project;
    //常见问题
    private TextView text_question;
//头布局


    //百分号
    private TextView text_baifen;
    //下拉刷新
    PullToRefreshScrollView sv;
    //百分号
    private TextView textbanfen1;
    //加号
    private TextView textjiahao;
    //百分号2
    private TextView text_baifen2;
    //内容布局
    private LinearLayout layout_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.v6dexterity2);
        textjiahao = (TextView) findViewById(R.id.text_baifen);
        text_baifen = (TextView) findViewById(R.id.text_baifen);
        textjiahao = (TextView) findViewById(R.id.textjiahao);
        text_baifen2 = (TextView) findViewById(R.id.text_baifen2);
        textbanfen1 = (TextView) findViewById(R.id.textbanfen1);
        sv = (PullToRefreshScrollView) findViewById(R.id.home_sv);
        layout_content = (LinearLayout) findViewById(R.id.layout_content);
        sv.getLoadingLayoutProxy().setPullLabel("下拉可刷新");
        sv.getLoadingLayoutProxy().setRefreshingLabel("智慧投资 更优一点");
        sv.getLoadingLayoutProxy().setReleaseLabel("松开即刷新");
        sv.setOnRefreshListener(this);
        initview();
    }

    private void initview() {
//        Toast.makeText(this, "智投宝", Toast.LENGTH_SHORT).show();

        ref = getShare().getString("usercode", "");


        tv_desc = (TextView) findViewById(R.id.tv_desc);


        tv_title = (TextView) findViewById(R.id.tv_title);
        //项目详情
        text_project = (TextView) findViewById(R.id.text_project);
        text_project.setOnClickListener(this);
        //常见问题
        text_question = (TextView) findViewById(R.id.text_question);
        text_question.setOnClickListener(this);
        et_amount = (TextView) findViewById(R.id.et_amount);
        v6_de_rate_up = (TextView) findViewById(R.id.v6_de_rate_up);
        v6_de_rate_dwon = (TextView) findViewById(R.id.v6_de_rate_dwon);

        tv_millionAccrua = (TextView) findViewById(R.id.tv_millionAccrua);
        btn_dexterity_invest = (Button) findViewById(R.id.btn_dexterity_invest);
//        btn_dexterity_invest.setVisibility(View.INVISIBLE);
        btn_dexterity_invest.setOnClickListener(this);
        View view = LayoutInflater.from(this)
                .inflate(R.layout.v6_pop_item, null);
        layout_calculator = (LinearLayout) view.findViewById(R.id.layout_calculator);
        layout_share = (LinearLayout) view.findViewById(R.id.layout_share);
        pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        pop.setOutsideTouchable(true);
        pop.setBackgroundDrawable(new BitmapDrawable());

        mAlertDialog = new GuideAlertDialog(this, this);
        mAlertDialog2 = new InvestLoginDialog(this, this);
//        rl_menu.setOnClickListener(this);
        layout_calculator.setOnClickListener(this);
        layout_share.setOnClickListener(this);
//        img_share.setOnClickListener(this);

        tv_title.setOnClickListener(this);
        initData(true);
    }

    private void initview2() {
//        Toast.makeText(this, "智投宝", Toast.LENGTH_SHORT).show();

        ref = getShare().getString("usercode", "");


        tv_desc = (TextView) findViewById(R.id.tv_desc);


        tv_title = (TextView) findViewById(R.id.tv_title);
        //项目详情
        text_project = (TextView) findViewById(R.id.text_project);
        text_project.setOnClickListener(this);
        //常见问题
        text_question = (TextView) findViewById(R.id.text_question);
        text_question.setOnClickListener(this);
        et_amount = (TextView) findViewById(R.id.et_amount);
        v6_de_rate_up = (TextView) findViewById(R.id.v6_de_rate_up);
        v6_de_rate_dwon = (TextView) findViewById(R.id.v6_de_rate_dwon);

        tv_millionAccrua = (TextView) findViewById(R.id.tv_millionAccrua);
        btn_dexterity_invest = (Button) findViewById(R.id.btn_dexterity_invest);
//        btn_dexterity_invest.setVisibility(View.INVISIBLE);
        btn_dexterity_invest.setOnClickListener(this);
        View view = LayoutInflater.from(this)
                .inflate(R.layout.v6_pop_item, null);
        layout_calculator = (LinearLayout) view.findViewById(R.id.layout_calculator);
        layout_share = (LinearLayout) view.findViewById(R.id.layout_share);
        pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        pop.setOutsideTouchable(true);
        pop.setBackgroundDrawable(new BitmapDrawable());

        mAlertDialog = new GuideAlertDialog(this, this);
        mAlertDialog2 = new InvestLoginDialog(this, this);
//        rl_menu.setOnClickListener(this);
        layout_calculator.setOnClickListener(this);
        layout_share.setOnClickListener(this);
//        img_share.setOnClickListener(this);

        tv_title.setOnClickListener(this);
        initData2(true);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return false;
    }

    private void shareLogin() {
        VolleryUtil vollery = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    pop.dismiss();
                    LogUtils.e(V6DexterityActivity2.this, jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");

                    if (getShare().getString("usercode", "").equals("")) {
                        linkurl = json1.optString("linkUrl");
                    } else {
                        linkurl = json1.optString("linkUrl") + "?ref=" + getShare().getString("usercode", "");

                    }
                    share(V6DexterityActivity2.this,
                            json1.optString("description"),
                            json1.optString("title"),
                            linkurl,
                            json1.optString("imageUrl"));
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };

        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setShow(true);
        vollery.setRequestMethod(0);
        vollery.execute(V6DexterityActivity2.this, Constant.URL
                + "/api/shareProductContent/" + type + "/" + "ztb", "");
    }

    private void userinfo() {
        VolleryUtil volleryUtil = new VolleryUtil() {
            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Intent intent = null;
                    JSONObject json = jsonObject.optJSONObject("data");
                    if ("false".equals(json.optString("isLogin"))) {
                   /*   mAlertDialog.show();
                        mAlertDialog.setText("投资前请登录～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("login");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("登录");*/

                        mAlertDialog2.show();
                        mAlertDialog2.setText("投资前请登录");
                        mAlertDialog2.setTitle("提示");
                        mAlertDialog2.setType("login");
                        mAlertDialog2.setButtonCancel("稍后");
                        mAlertDialog2.setButtonsure("登录");
                        return;
                    }
                    if ("false".equals(json.optString("isIdAuth"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先绑定银行卡～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("bindcard");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("绑定银行卡");

                        return;
                    }
                    if ("false".equals(json.optString("isSetPayPwd"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先设置交易密码～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("password");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("设置交易密码");
                        return;
                    }
                    if ("false".equals(json.optString("isRiskAssessment"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先风险测评～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("ceping");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("风险测评");
                        return;

                    }
                    intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
//                    intent = new Intent(V6DexterityActivity2.this, V6WebviewChild3.class);
//                    intent.putExtra("url", Constant.URL + "h5/helpCurrent?app=true&token=");
//                    Constant.URL + "api/v3/claim/fund/intelliInto" + "?app=true&token=" + getURLToken()
//                    intent.putExtra("url", Constant.URL + "api/v3/claim/fund/intelliInto");
//                    intent.putExtra("url", Constant.URL + "api/v3/claim/fund/intelliInto" + "?app=true");
                    intent.putExtra("url", Constant.URL + "api/v3/claim/fund/intelliInto" + "?app=true&token=");
                    startActivity(intent);
                } else {
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.execute(V6DexterityActivity2.this, Constant.URL + "/api/v6/render/intelliDeposit", "");
    }

    private void initData(boolean show) {
        // TODO Auto-generated method stub
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                LogUtils.e(V6DexterityActivity2.this, "智投宝" + jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
//                    setContentInview(V6DexterityActivity2.this).setVisibility(View.VISIBLE);

                    iv_v4_nonetwork1.setVisibility(View.GONE);
                    layout_content.setVisibility(View.VISIBLE);
                    sv.setVisibility(View.VISIBLE);
                    btn_dexterity_invest.setVisibility(View.VISIBLE);


                    JSONObject json1 = jsonObject.optJSONObject("data");
//
                    Gson gson = new Gson();
                    type = json1.optString("productType");
                    list = gson.fromJson(json1.optString("characterList"), new TypeToken<ArrayList<String>>() {
                    }.getType());
                    increaseNum = json1.optInt("increaseNum");
//                    rulerView.setTextIncreaseNum(increaseNum);
                   /* if ("downCount".equals(json1.optString("intelliStatus"))) {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        long now = json1.optLong("now");
                        long end = json1.optLong("openDate");
                        long keyong = end - now;
                        btn_dexterity_invest.setText("即将开放");
                        btn_dexterity_invest.setEnabled(false);
                    } else if ("opening".equals(json1.optString("intelliStatus"))) {

                        btn_dexterity_invest.setBackgroundResource(R.drawable.v6button);
                        btn_dexterity_invest.setText("转入");
                        btn_dexterity_invest.setEnabled(true);
                    } else {


                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        btn_dexterity_invest.setText("已售罄");
                        btn_dexterity_invest.setEnabled(false);
                    }*/

                    Gson gson2 = new Gson();
                    ZhiTouBaoModel zhiTou = new ZhiTouBaoModel();
                    zhiTou = gson2.fromJson(jsonObject.toString(), ZhiTouBaoModel.class);
                    ZhiTouBaoModel.DataBean.IntelliRateBean intelliRate = new ZhiTouBaoModel.DataBean.IntelliRateBean();
                    intelliRate = zhiTou.getData().getIntelliRate();
                    Double d = zhiTou.getData().getIntelliLimit().getRemainAmount();
                    if (zhiTou.getData().getIntelliLimit() != null && d.intValue() > 0) {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.v6button);
                        btn_dexterity_invest.setText("立即转入");
                        btn_dexterity_invest.setEnabled(true);
                    } else {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        btn_dexterity_invest.setText("已售罄");
                        btn_dexterity_invest.setEnabled(false);
                    }

                /*    private TextView textjiahao;
                    //百分号
                    private TextView text_baifen;*/
//                    h.tv_rate.setText(Regular.getDecimalFormatTwo(Double.parseDouble(list.get(position).getRate())-Double.parseDouble(list.get(position).getRateAdd())));
                    if (TextUtils.isEmpty(intelliRate.getRewardRateAdd())) {
                        textjiahao.setVisibility(View.GONE);
                        text_baifen.setVisibility(View.GONE);
                        v6_de_rate_up.setVisibility(View.GONE);
                    } else {
//                        v6_de_rate_up.setText(intelliRate.getRewardRateAdd());
                        v6_de_rate_up.setText(Regular.getDecimalFormatTwo(Double.parseDouble(intelliRate.getRewardRateAdd())));
                        text_baifen2.setVisibility(View.VISIBLE);
                        textjiahao.setVisibility(View.VISIBLE);
                    }

                    textbanfen1.setVisibility(View.VISIBLE);

//                    v6_de_rate_dwon.setText(intelliRate.getFixedRate());
                    v6_de_rate_dwon.setText(Regular.getDecimalFormatTwo(Double.parseDouble(intelliRate.getFixedRate())));
//                    tv_every_day.setText(json1.optString("betweenProfit"));
                    millionAccrua = json1.optDouble("millionAccrual");
                    tv_millionAccrua.setText("每日万元收益：" + zhiTou.getData().getExpectedNum() + "元");
//                    tv_year.setText(json1.optString("holdCap"));
                    rate = json1.optDouble("rate");
                    id = json1.optString("productId");
                    flag = json1.optBoolean("flagFresh");

                } else {

                    iv_v4_nonetwork1.setVisibility(View.VISIBLE);
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

//                setContentInview(V6DexterityActivity2.this).setVisibility(View.VISIBLE);

                iv_v4_nonetwork1.setVisibility(View.GONE);

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(show);
        volleryUtil.setHeaders("token", getToken());
//        volleryUtil.execute(V6DexterityActivity2.this, Constant.URL + "/api/v6/render/intelliDeposit", "");
        volleryUtil.execute(V6DexterityActivity2.this, Constant.URL + "/api/v7/render/intelliDeposit", "");
    }

    private void initData2(boolean show) {
        // TODO Auto-generated method stub
        VolleryUtil3 volleryUtil = new VolleryUtil3() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                LogUtils.e(V6DexterityActivity2.this, "智投宝" + jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
//                    setContentInview(V6DexterityActivity2.this).setVisibility(View.VISIBLE);

                    iv_v4_nonetwork1.setVisibility(View.GONE);
                    btn_dexterity_invest.setVisibility(View.VISIBLE);


                    JSONObject json1 = jsonObject.optJSONObject("data");
//
                    Gson gson = new Gson();
                    type = json1.optString("productType");
                    list = gson.fromJson(json1.optString("characterList"), new TypeToken<ArrayList<String>>() {
                    }.getType());
                    increaseNum = json1.optInt("increaseNum");
//                    rulerView.setTextIncreaseNum(increaseNum);
                   /* if ("downCount".equals(json1.optString("intelliStatus"))) {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        long now = json1.optLong("now");
                        long end = json1.optLong("openDate");
                        long keyong = end - now;
                        btn_dexterity_invest.setText("即将开放");
                        btn_dexterity_invest.setEnabled(false);
                    } else if ("opening".equals(json1.optString("intelliStatus"))) {

                        btn_dexterity_invest.setBackgroundResource(R.drawable.v6button);
                        btn_dexterity_invest.setText("转入");
                        btn_dexterity_invest.setEnabled(true);
                    } else {


                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        btn_dexterity_invest.setText("已售罄");
                        btn_dexterity_invest.setEnabled(false);
                    }*/

                    Gson gson2 = new Gson();
                    ZhiTouBaoModel zhiTou = new ZhiTouBaoModel();
                    zhiTou = gson2.fromJson(jsonObject.toString(), ZhiTouBaoModel.class);
                    ZhiTouBaoModel.DataBean.IntelliRateBean intelliRate = new ZhiTouBaoModel.DataBean.IntelliRateBean();
                    intelliRate = zhiTou.getData().getIntelliRate();
                    Double d = zhiTou.getData().getIntelliLimit().getRemainAmount();
                    if (zhiTou.getData().getIntelliLimit() != null && d.intValue() > 0) {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.v6button);
                        btn_dexterity_invest.setText("立即转入");
                        btn_dexterity_invest.setEnabled(true);
                    } else {
                        btn_dexterity_invest.setBackgroundResource(R.drawable.btn_unclick);
                        btn_dexterity_invest.setText("已售罄");
                        btn_dexterity_invest.setEnabled(false);
                    }

                /*    private TextView textjiahao;
                    //百分号
                    private TextView text_baifen;*/
//                    h.tv_rate.setText(Regular.getDecimalFormatTwo(Double.parseDouble(list.get(position).getRate())-Double.parseDouble(list.get(position).getRateAdd())));
                    if (TextUtils.isEmpty(intelliRate.getRewardRateAdd())) {
                        textjiahao.setVisibility(View.GONE);
                        text_baifen.setVisibility(View.GONE);
                        v6_de_rate_up.setVisibility(View.GONE);
                    } else {
//                        v6_de_rate_up.setText(intelliRate.getRewardRateAdd());
                        v6_de_rate_up.setText(Regular.getDecimalFormatTwo(Double.parseDouble(intelliRate.getRewardRateAdd())));
                        text_baifen2.setVisibility(View.VISIBLE);
                        textjiahao.setVisibility(View.VISIBLE);
                    }

                    textbanfen1.setVisibility(View.VISIBLE);

//                    v6_de_rate_dwon.setText(intelliRate.getFixedRate());
                    v6_de_rate_dwon.setText(Regular.getDecimalFormatTwo(Double.parseDouble(intelliRate.getFixedRate())));
//                    tv_every_day.setText(json1.optString("betweenProfit"));
                    millionAccrua = json1.optDouble("millionAccrual");
                    tv_millionAccrua.setText("每日万元收益：" + zhiTou.getData().getExpectedNum() + "元");
//                    tv_year.setText(json1.optString("holdCap"));
                    rate = json1.optDouble("rate");
                    id = json1.optString("productId");
                    flag = json1.optBoolean("flagFresh");

                } else {

                    iv_v4_nonetwork1.setVisibility(View.VISIBLE);
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

//                setContentInview(V6DexterityActivity2.this).setVisibility(View.VISIBLE);

                iv_v4_nonetwork1.setVisibility(View.GONE);

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(show);
        volleryUtil.setHeaders("token", getToken());
//        volleryUtil.execute(V6DexterityActivity2.this, Constant.URL + "/api/v6/render/intelliDeposit", "");
        volleryUtil.execute(V6DexterityActivity2.this, Constant.URL + "/api/v7/render/intelliDeposit", "");
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
//        initData(false);

        iv_v4_nonetwork1 = (ImageView) findViewById(R.id.iv_v4_nonetwork1);
        iv_v4_nonetwork1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!network()) {
                    Toast.makeText(V6DexterityActivity2.this, "当前无网络", Toast.LENGTH_SHORT).show();
                }

                initview();
                initData(true);
            }
        });

  if (!network()) {

            iv_v4_nonetwork1.setVisibility(View.VISIBLE);
            layout_content.setVisibility(View.GONE);
            sv.setVisibility(View.GONE);
        } else {

            layout_content.setVisibility(View.VISIBLE);
            sv.setVisibility(View.VISIBLE);
            iv_v4_nonetwork1.setVisibility(View.GONE);

            if (TextUtils.isEmpty(v6_de_rate_dwon.getText().toString())) {

            } else {
                initData(true);
            }


        }
    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (v.getId()) {
            case R.id.btn_dexterity_invest:

                userinfo();
                break;
//关于智投宝
       /*     case R.id.img_ico:
                intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/helpCurrent?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;*/
            case R.id.tv_title:
                intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);

                intent.putExtra("url", Constant.URL + "h5/helpCurrent?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case R.id.layout_share:
                shareLogin();
                break;

            case R.id.layout_calculator:
                intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/calculator?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                pop.dismiss();
//			ToastUtil.showCenterToast(V6DexterityActivity.this, "计算器");
                break;
         /*   private TextView text_project;
            //常见问题
            private TextView text_question;*/

            //项目详情
            case R.id.text_project:
//                Toast.makeText(this, "跳转到项目详情", Toast.LENGTH_SHORT).show();
                intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
//                intent0.putExtra("url", Constant.URL + "h5/assess/index" + "?showHeader=1&app=true&token=");
                intent.putExtra("url", Constant.URL + "h5/helpCurrent?type=0" + "&app=true&token=");
                startActivity(intent);
//                ProjectDetail_QuestionActivity   项目详情
                break;

            case R.id.text_question:
//                Toast.makeText(this, "跳转到常见问题", Toast.LENGTH_SHORT).show();
                intent = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/helpCurrent?type=1" + "&app=true&token=");

                startActivity(intent);
                break;

        }
    }


    @Override
    public void onConfirm() {
        //需求量不大 暂且不使用枚举
        Intent intent = null;
        switch (mAlertDialog.getType()) {

            case "bindcard":
                intent = new Intent(V6DexterityActivity2.this,
                        V6WebviewChild.class);
//                intent0.putExtra("url", Constant.URL + "h5/assess/index" + "?showHeader=1&app=true&token=");
                intent.putExtra("url", Constant.URL + "h5/account/bankcard/bind/view?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case "password":
                intent = new Intent(V6DexterityActivity2.this,
                        Set_tr_pw.class);
                startActivity(intent);
                break;
            case "ceping":
                Intent intent0 = null;

                intent0 = new Intent(V6DexterityActivity2.this, V6WebviewChild.class);
                intent0.putExtra("url", Constant.URL + "h5/assess/index" + "?showHeader=1&app=true&token=");
                startActivity(intent0);
                break;
            case "login":
                intent = new Intent(V6DexterityActivity2.this,
                        V6LoginActivity.class);
                intent.putExtra("close", 1);

                startActivityForResult(intent, 1);
                break;
        }

    }


    @Override
    public void onConfirm2() {
        Intent intent = null;
        switch (mAlertDialog2.getType()) {
            case "login":
                intent = new Intent(V6DexterityActivity2.this,
                        V6LoginActivity.class);
                intent.putExtra("close", 1);

                startActivityForResult(intent, 1);
                break;

        }

    }

    @Override
    public void onCancle() {
        // TODO Auto-generated method stub
//		ToastUtil.showCenterToast(V6DexterityActivity.this, "取消");
    }

    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {

            initview2();

            sv.onRefreshComplete();

        }

    };

    @Override
    public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {

        // TODO Auto-generated method stub
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

                handler.sendEmptyMessage(1);
            }
        }, 1000);
    }
}
